import myRequest from '../request.js'

import dicts from '@/config/dicts.js'

// ALL:全部,WAIT_PAY:待付款,WAIT_SHIP:待发货,
// WAIT_ROG: 待收货, COMPLETE: 已完成, AFTER_SALE: 退款&售后
export const queryOrder = (params) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + '/purchaser/order/order', 'get', params).then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 确认收货
export const confirmReceipt = (orderSn) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/order/order/${orderSn}/receiving`, 'post').then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 取消订单
export const cancellationOrder = (orderSn, reason = "") => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/order/order/${orderSn}/cancel`, 'post', { reason }).then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 查看物流  
export const getLogistics = (orderSn) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/order/order/getTraces/${orderSn}`, 'post').then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 订单再次购买
export const orderAgainPay = (orderSn) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/trade/carts/order/again`, 'post', { orderSn: orderSn }).then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 提醒发货 
export const remindShipment = (orderSn) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/order/order/${orderSn}/bring`, 'get').then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 删除订单
export const deleteOrder = (orderSn) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/order/order/${orderSn}`, 'delete').then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 查看物流
export const checkLogistics = (orderSn) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/order/order/traces/${orderSn}`, 'post').then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 订单明细
export const orderDetails = (orderSn, val) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/order/order/${orderSn}`, 'get', val).then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 售后列表
export const getAfterSalesList = (val) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/order/afterSale/page`, 'get', val).then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 获取售后订单详情
export const getAfterOrderInfo = (sn) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/order/afterSale/get/${sn}`, 'get').then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 获取 退货 收货地址信息
export const getAfterSalesAddres = () => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.essential + '/common/common/address/returnAddress', 'get').then(res => {
      resolve(res)
    }).catch(err => { reject(err) })
  })
}
// 获取售后原因
export const getAfterSalesReason = (serviceType) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + '/purchaser/order/afterSale/get/afterSaleReason/' + serviceType, 'get').then(res => {
      resolve(res)
    }).catch(err => { reject(err) })
  })
}
// 申请售后
export const applyAfterSales = (orderItemSn, val) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + '/purchaser/order/afterSale/save/' + orderItemSn, 'post', val, { 'Content-type': "application/json" }).then(res => {
      resolve(res)
    }).catch(err => { reject(err) })
  })
}
// 出库单查询
export const outBoundQuery = (orderSn) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/order/order/${orderSn}/outboundOrder`, 'get').then(res => {
      resolve(res)
    }).catch(err => { reject(err) })
  })
}
// 获取订单中商品药检报告图片地址
export const getDrugTestImage = (orderSn, val) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/order/order/${orderSn}/inspectionReports`, 'get', val).then(res => {
      resolve(res)
    }).catch(err => { reject(err) })
  })
}
// 再次购买
export const buyAgain = (orderSn) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/order/order/${orderSn}/available/skus`, 'get').then(res => {
      resolve(res)
    }).catch(err => { reject(err) })
  })
}

